import request from '@/utils/request'

export function apiGetList(params, loading) {
  return request({
    url: `/permission/userController/list`,
    method: 'get',
    params,
    loading,
    autoUntie: false,
  })
}

export function apiRefer(params, loading) {
  return request({
    url: `/permission/userQueryController/referGrid`,
    method: 'get',
    params,
    loading,
    autoUntie: false,
  })
}

export function apiAdd(data) {
  return request({
    url: '/permission/userController/add',
    method: 'post',
    data: data,
  })
}
export function apiEdit(data) {
  return request({
    url: '/permission/userController/edit',
    method: 'put',
    data: data,
  })
}

export function apiDel(id) {
  return request({
    url: '/permission/userController/delete',
    method: 'delete',
    data: { id },
  })
}

export function apiEditPwd(data, loading) {
  return request({
    url: '/permission/userController/changePassword',
    method: 'post',
    data: data,
    loading,
  })
}

export function apiUnlock(id) {
  return request({
    url: '/permission/userController/unLock',
    method: 'post',
    data: { id },
  })
}
export function apiDisable(id) {
  return request({
    url: '/permission/userController/disable',
    method: 'post',
    data: { id },
  })
}

export function apiEnable(id) {
  return request({
    url: '/permission/userController/enable',
    method: 'post',
    data: { id },
  })
}

export function apiResign(id) {
  return request({
    url: '/permission/userController/resign',
    method: 'post',
    data: { id },
  })
}

export function apiRehiring(id) {
  return request({
    url: '/permission/userController/rehiring',
    method: 'post',
    data: { id },
  })
}

// 关联角色
export function apiRelationRole(data, loading) {
  return request({
    url: '/permission/roleUserController/addLinkForTarget',
    method: 'post',
    data,
    loading,
  })
}

export function apiGetDepTree(params) {
  return request({
    url: `/org/deptController/listHasChildren`,
    method: 'get',
    params,
    resField: 'data',
  })
}
// 获取关联的角色
export function apiGetLinkRoles(ids) {
  return request({
    url: '/permission/roleUserController/listSources?targetIds=' + ids,
    method: 'get',
    resField: 'data',
  })
}

// 导出
export function apiExport(params, loading){
  return request({
    url: '/permission/userController/export',
    method: 'get',
    responseType: 'blob',
    params,
    loading
  })
}